package com.lyrcsoft.rokectmq;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.io.UnsupportedEncodingException;

/**
 * @author fujc2dev@126.com
 * @date 2024-05-09 14:41
 */
public class SendOnewayProducer {
    public static void main(String[] args) throws MQClientException, UnsupportedEncodingException, RemotingException, InterruptedException {
        DefaultMQProducer producer = new DefaultMQProducer("producer_group");
        producer.setNamesrvAddr("10.20.200.144:9876");
        producer.start();
        for (int i = 0; i < 10; i++) {
            // 创建消息
            String body = "Hello RocketMQ " + i;
            Message msg = new Message("TopicTest", "TagA", body.getBytes(RemotingHelper.DEFAULT_CHARSET));
            producer.sendOneway(msg);
        }
        producer.shutdown();

    }
}
